<template>
    <div>
        <NavBar :title="title"></NavBar>
        <van-row>
            <van-col span="6">
                <van-sidebar v-model="active">
                    <van-sidebar-item v-for="item in categoriesApiData" :title="item.cat_name" />

                </van-sidebar>

            </van-col>
            <van-col span="18">

                <van-search v-model="value" show-action label="地址" placeholder="请输入搜索关键词" @search="onSearch">
                    <template #action>
                        <div @click="onClickButton">搜索</div>
                    </template>
                </van-search>
                <Swipe :images="images" :imgwidth="imgwidth" :imgheight="imgheight"></Swipe>
                <van-skeleton title :row="13" v-show="start" />
                <div v-for="item in categoriesApiData[active]?.children" v-show="!start">
                    
                    <h3>{{ item.cat_name }}</h3>
                    <router-link :to="{ name: 'goods', params: { query: item.cat_name } }">
                        <van-grid :column-num="4">
                            <van-grid-item v-for="items in item.children" :icon="items.cat_icon"
                                :text="items.cat_name" />
                        </van-grid>
                    </router-link>


                </div>
            </van-col>

        </van-row>
    </div>
</template>

<script setup>
import NavBar from '@/components/NavBar.vue';
const title = '分类'
import Swipe from '@/components/Swipe.vue';
const images = [
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-1.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-2.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-3.jpeg',
    'https://fastly.jsdelivr.net/npm/@vant/assets/apple-4.jpeg',
];
const imgwidth = '100%'
const imgheight = '200px'
import { ref } from 'vue';
const active = ref(0)
const start = ref(true)
const categoriesApiData = ref([])
import { categoriesApi } from '@/api/api';
categoriesApi().then(res => {
    console.log(res);
    categoriesApiData.value = res.data.message
    if (res.data.message.length > 0) {
        start.value = false
    } else {
        start.value = true
    }
})

</script>

<style lang="scss" scoped></style>